let productId = sessionStorage.getItem("productId");
$(function () {

    $.ajax({
        url:"http://localhost:8080/back/font/findNavById",
        data:{"id":productId},
        dataType:"json",
        headers:{'username':localStorage.getItem("loginUser")},
        success:function (res) {
            console.log("产品编辑页面根据id返回的数据",res)
            setData(res.data)
        }
    })
})


//设置数据到产品编辑页面
function setData(data) {


    layui.use(['upload', 'element', 'layer', 'layedit', 'form'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer
            , form = layui.form
            , layedit = layui.layedit;



        $("#title").val(data.title);

        $("#href").val(data.titleHref);

        //监听修改提交
        //提交编辑内容
        form.on('submit(edit)',
            function (data) {
                /*data.field.enable = (data.field.enable == '启用')?1:0;
                 let attr = $('input[type="checkbox"][name="hobby"]:checked').each(function () {
                     hobby.push($(this).attr("title"));
                 })*/
                //js向对象中添加新的属性
                console.log("提交的id", data.field.id);
                data.field.id = productId ;
                console.log("提交的内容", data.field);

                $.ajax({
                    url: "http://localhost:8080/back/font/updateFoot",
                    type: "post",
                    headers:{'username':localStorage.getItem("loginUser")},
                    data:  JSON.stringify(data.field),
                    contentType:"application/json",
                    dataType: "json",
                    success: function (res) {
                        if (res.msg == "success") {
                            //发异步，把数据提交给php
                            layer.alert("修改成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();

                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.alert("修改失败");
                        }
                    }
                })


                return false;
            });

    });
}